package cn.easybuy.service.impl;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import cn.easybuy.dao.searchDao;
import cn.easybuy.dao.impl.searchDaoImput;
import cn.easybuy.entity.Page1;
import cn.easybuy.entity.Product;
import cn.easybuy.entity.search;
import cn.easybuy.service.searchDaoService;
import cn.easybuy.utils.DataSourceUtil;

public class searchDaoServiceImput implements searchDaoService{

	Connection con=DataSourceUtil.getConnection();
	searchDao dao=new searchDaoImput(con);
	//閿熸枻鎷烽敓鏂ゆ嫹閿熺嫛鍑ゆ嫹閿熺嫛鏂ゆ嫹閿熷彨璇ф嫹璇㈤敓鏂ゆ嫹妯￠敓鏂ゆ嫹閿熺獤顖ゆ嫹閿燂拷
	@Override
	public List<search> seleSearch(search se, Page1 page1,String name) {
		// TODO Auto-generated method stub
		List<search> list=new ArrayList<search>();
		try {
			int count=dao.count(name);		//閿熸枻鎷烽敓鏂ゆ嫹閿熸彮绛规嫹閿燂拷
			page1.setCount(count);		//閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽〉閿熸枻鎷�
			if(page1.getCurrendPage()>page1.getCountPage()){
				page1.setCurrendPage(page1.getCountPage());
			}else if(page1.getCurrendPage()<1){
				page1.setCurrendPage(1);
			}
			list=dao.seleSearch(se, page1, name);
			page1.setSizeList(list);
		} catch (Exception e) {
			System.out.println(e);
		}
		return list;
	}
	@Override
	public List<search> listId(int id, Page1 page1) throws Exception{
		Connection conn=DataSourceUtil.getConnection();
		try{			
			return new searchDaoImput(conn).listId(id, page1);
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}finally{
			DataSourceUtil.closeAll(conn, null, null);
		}
	}
	@Override
	public int countId(int id) throws Exception{
		Connection conn=DataSourceUtil.getConnection();
		try{			
			return new searchDaoImput(conn).countId(id);
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}finally{
			DataSourceUtil.closeAll(conn, null, null);
		}
	}
	@Override
	public List<Product> list(String [] ids) throws Exception{
		Connection conn=DataSourceUtil.getConnection();
		try{			
			return new searchDaoImput(conn).list(ids);
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}finally{
			DataSourceUtil.closeAll(conn, null, null);
		}
	}
	
}
